#include <iostream>
#include <string>
using namespace std;

string capitalizeTitle(string title) {
    int n = title.size();
    int pos = 0;
    while(pos < n) {
        int cnt = 0;
        while(pos+cnt < n && title[pos+cnt] != ' ') cnt++;
        if(cnt == 1 || cnt == 2) {
            while(title[pos] != ' ') {
                title[pos++] = tolower(title[pos]);
            }
        }else {
            title[pos++] = toupper(title[pos]);
            while(title[pos] != ' ') {
                title[pos++] = tolower(title[pos]);
            }
        }
        pos++;
    }
    return title;
}
